import pygame


class Button:
    """按钮"""
    def __init__(self, ai_game, msg):
        """初始化按钮属性"""
        self.screen = ai_game.screen

        # 设置按钮的尺寸和其他属性
        self.width, self.height = 200, 50
        self.button_color = (100, 100, 100)
        self.text_color = (255, 255, 255)
        self.font = pygame.font.SysFont(None, 48)

        self._prep_msg(msg)

    def _prep_msg(self, msg):
        """将msg渲染为图像"""
        self.msg_imgae = self.font.render(msg, True, self.text_color,
                                          self.button_color)
        self.msg_imgae_rect = self.msg_imgae.get_rect()

    def draw_button(self):
        screen_rect = self.screen.get_rect()
        self.rect = pygame.Rect(0, 0, self.width, self.height)
        self.rect.center = screen_rect.center
        self.msg_imgae_rect.center = screen_rect.center
        self.screen.fill(self.button_color, self.rect)
        self.screen.blit(self.msg_imgae, self.msg_imgae_rect)
